package com.wolfcode.goodsstore.controller;

import com.wolfcode.common.annotation.Log;
import com.wolfcode.common.core.controller.BaseController;
import com.wolfcode.common.core.domain.AjaxResult;
import com.wolfcode.common.core.page.TableDataInfo;
import com.wolfcode.common.enums.BusinessType;
import com.wolfcode.goodsstore.domain.GoodsStore;
import com.wolfcode.goodsstore.domain.info.GoodsStoreInfo;
import com.wolfcode.goodsstore.domain.vo.GoodsStoreVo;
import com.wolfcode.goodsstore.service.IGoodsStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 物品库存Controller
 *

/**
 * 物品库存Controller
 *
 * @author wolfcode
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/goodsstore/store")
public class GoodsStoreController extends BaseController
{
    @Autowired
    private IGoodsStoreService goodsStoreService;

    /**
     * 查询物品库存列表
     */
    @PreAuthorize("@ss.hasPermi('goodsstore:store:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsStoreVo goodsStore)
    {
        startPage();
        List<GoodsStoreInfo> list = goodsStoreService.selectGoodsStoreList(goodsStore);
        return getDataTable(list);
    }


    /**
     * 获取物品库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('goodsstore:store:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(goodsStoreService.selectGoodsStoreById(id));
    }

    /**
     * 新增物品库存
     */
    @PreAuthorize("@ss.hasPermi('goodsstore:store:add')")
    @Log(title = "物品库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsStore goodsStore)
    {
        return toAjax(goodsStoreService.insertGoodsStore(goodsStore));
    }

    /**
     * 修改物品库存
     */
    @PreAuthorize("@ss.hasPermi('goodsstore:store:edit')")
    @Log(title = "物品库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsStore goodsStore)
    {
        return toAjax(goodsStoreService.updateGoodsStore(goodsStore));
    }

    /**
     * 删除物品库存
     */
    @PreAuthorize("@ss.hasPermi('goodsstore:store:remove')")
    @Log(title = "物品库存", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodsStoreService.deleteGoodsStoreByIds(ids));
    }
}
